#include <bits/stdc++.h>
using namespace std;
int N, M, J;

int main() {
    int res = 0;
    cin >> N >> M >> J;
    int l = 1, r = 1 + M - 1, down;
    while (J--) {
        cin >> down;
        if (down < l) {
            res += (l - down);
            l = down; r = l + M - 1;
        }
        else if (down > r) {
            res += (down - r);
            r = down; l = r - M + 1;
        }
    }
    cout << res << endl;
    return 0;
}